''' 生成器
    一边用一边生成
'''

# def  f():
#     print("生成1")
#     yield 1
#     print("生成2")
#     yield 2
#     print("生成3")
#     yield 3
#
#
# g = f()
# it = iter(g)
#
# print(next(it))
# print(next(it))
# print(next(it))


'''
练习
分别写两个生成器函数，分别生成1-100的整数，1-100的奇数
'''
#
# def yia_int():
#     for i in range(101):
#         yield i
#
# it = iter(yia_int())
#
# while True:
#     try:
#         print(next(it),end=' ')
#     except StopIteration:
#         break
#
# print()
# def yia_j():
#     for i in range(1,101,2):
#         yield i
#
# it = yia_j()
#
# while True:
#     try:
#         print(next(it),end=' ')
#     except StopIteration:
#         break
#


''' 生成器推导式'''

gen = (x**x for x in range(1,5))

print(next(gen))
print(next(gen))
print(next(gen))
print(next(gen))